
func isPaired*(text: string): bool =
  var
    stack: seq[char]

  for ch in text:
    case ch:
      of '{':
        stack.add '}'
      of '[':
        stack.add ']'
      of '(':
        stack.add ')'
      of '}', ']', ')':
        if stack.len == 0 or stack.pop() != ch:
          return false
      else:
        discard

  stack.len == 0